package com.young.shop.controller;

import com.young.shop.dao.UserDao;
import com.young.shop.dao.impl.UserDaoImpl;
import com.young.shop.pojo.entity.User;
import com.young.shop.pojo.vo.BaseRespVO;
import com.young.shop.service.UserService;
import com.young.shop.service.impl.UserServiceImple;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/JS")
public class JudgeState extends BaseController {
    private UserDao userDao=new UserDaoImpl();
    @Override
    protected void doGet(HttpServletRequest req , HttpServletResponse resp) throws ServletException, IOException {
        //判断session有没有值
        HttpSession session = req.getSession();
        User user =(User) session.getAttribute("client");
        long id = user.getId();

        //未登录状态
        if (user==null){
            //未登录状态
            BaseRespVO baseRespVO = new BaseRespVO();
            baseRespVO.setCode(100);
            baseRespVO.setMsg("请先登录");
            //未登录状态 返回状态值100 已经msg信息
            writerBaseRespVoToResponse(resp,baseRespVO);
            return;

        }
        User dbUser = userDao.selectByID(id);
        //有登录情况下，返回一个对象
        writerSucccessBaseRespVoToResponse(resp,dbUser);
    }
}
